import { _decorator, Component, Node, Animation } from 'cc';
import { ReactiveNumber } from '../../../scripts/libs/rxjs/cc3/ReactiveNumber';
import { BaseView } from '../../../scripts/libs/rxjs/cc3/BaseView';
import { find } from 'cc';
import { ParticleSystem2D } from 'cc';
import { Colors } from '../../scripts/game/basic';
import { Timer } from '../../../scripts/libs/rxjs/cc3/CreatorSchedule';
import { Subscription } from 'rxjs';
import { nullifySubscription } from '../../../scripts/libs/rxjs/utils';
import { ResourceHelper } from '../../scripts/ResourceHelper';
import { AnimationPlay } from '../../../scripts/libs/rxjs/cc3/AnimationPlay';
const { ccclass, property } = _decorator;

@ccclass('Burst1')
export class Burst1 extends BaseView {

    // @property(ReactiveNumber)
    // _colorId: ReactiveNumber = ReactiveNumber.DefaultValue(null);
    // @property
    // get colorId(): number { return this._colorId.value }
    // set colorId(v: number) { this._colorId.Value = v; }

    // useObserves() {
    //     return [
    //         this._colorId.subscribe(this.refreshColor.bind(this)),
    //     ];
    // }

    onDestroyView(): void {
        nullifySubscription.call(this, '_sub');
    }

    // refreshColor() {
    //     if (this.colorId == null) return;
    //     let ps2d = find('dot', this.node).getComponent(ParticleSystem2D);
    //     ps2d.startColor = Colors[this.colorId];
    //     ps2d.endColor = Colors[this.colorId];
    // }

    _sub: Subscription = null;
    burst() {
        nullifySubscription.call(this, '_sub');
        this._sub = AnimationPlay(this.getComponent(Animation), 'circle').subscribe({
            complete: () => {
                ResourceHelper.Burst1Pool.putNode(this.node);
            }
        });
    }
}

